﻿using AccumulateApp.Helper;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Interactivity;

namespace AccumulateApp.Behavior
{
    public class WindowButtonBehavior: Behavior<System.Windows.Controls.Button>
    {
        private Window _window;
        public string Behavior { get; set; }

        protected override void OnAttached()
        {
            base.OnAttached();
            AssociatedObject.Click += AssociatedObject_Click;
            _window = CommonHelper.FindVisualParent<Window>(AssociatedObject);
        }

        protected override void OnDetaching()
        {
            base.OnDetaching();
            AssociatedObject.Click -= AssociatedObject_Click;
        }

        private void AssociatedObject_Click(object sender, RoutedEventArgs e)
        {
            var element = sender as System.Windows.Controls.Button;
            if (element == null)
                return;

            if (Behavior == "Close")
            {
                _window.Close();
            }
            else if (Behavior == "Min")
            {
                _window.WindowState = WindowState.Minimized;
            }
            else if (Behavior == "Max")
            {

            }
        }
    
    }
}
